from selenium import webdriver
import unittest
from selenium.webdriver.common.by import By
import traceback
from time import sleep
class Login(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:#
        cls.driver=webdriver.Chrome()
        cls.driver.get('http://192.168.4.16/upload/user.php')
        cls.driver.maximize_window()

    def setUp(self) -> None:
        pass

    def tearDown(self) -> None:
        pass

    @classmethod
    def tearDownClass(cls) -> None:
        cls.driver.quit()

    def test_s01(self):
        self.driver.find_element(By.NAME,'username').send_keys('sdd')
        self.driver.find_element(By.NAME, 'password').send_keys('123456')
        self.driver.find_element(By.NAME, 'submit').click()
        sleep(2)
        exp = '退出'
        rel = self.driver.find_element(By.LINK_TEXT, '退出').text
        if exp == rel:
            print('第一条用例OK')
        else:
            print('第一条用例NG')
        sleep(2)
    def test_f02(self):
        self.driver.find_element(By.NAME,'username').send_keys('sdd1')
        self.driver.find_element(By.NAME, 'password').send_keys('123456')
        self.driver.find_element(By.NAME, 'submit').click()
        sleep(2)
        exp='用户名或密码错误'
        rel=self.driver.find_element(By.XPATH,'//p[text()="用户名或密码错误"]').text
        if exp==rel:
            print('第二条用例OK')
        else:
            print('第二条用例NG')
        sleep(2)
    def test_f03(self):
        self.driver.find_element(By.NAME,'username').send_keys('sdd')
        self.driver.find_element(By.NAME, 'password').send_keys('1234561')
        self.driver.find_element(By.NAME, 'submit').click()
        sleep(2)
        exp = '用户名或密码错误'
        rel = self.driver.find_element(By.XPATH,'//p[text()="用户名或密码错误"]').text
        if exp == rel:
            print('第三条用例OK')
        else:
            print('第三条用例NG')
        sleep(2)
if __name__ == '__main__':
    unittest.main()

